<!doctype html>
<html><head>
	<meta charset="utf-8">
	<title>[(${dto.menu.title})]</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="icon" type="image/x-icon" href="/static/img/favicon.ico">
	
	<!-- jQuery-->
	<script type="text/javascript" src="/static/plugins/jquery/jquery-3.6.0.min.js"></script>
	
	<!-- layui-->
	<link rel="stylesheet" href="/static/plugins/layui/2.8.4/css/layui.css" media="all">
	<script src="/static/plugins/layui/2.8.4/layui.js" charset="utf-8"></script>
	
	<!-- common -->
	<link rel="stylesheet" href="/static/admin/css/common.css" media="all" />
	<script type="text/javascript" src="/static/admin/js/common-grid.js?v=c"></script>
	<link rel="stylesheet" href="/static/admin/css/mini-ease.css" media="all" />
	
	<!-- iconfont -->
	<link rel="stylesheet" href="/static/css/icon/iconfont.css" media="all" />
	
</head>
<body style="padding: 10px 0 0 10px;">
	
	<div class="layui-row layui-col-space5" style="width:100%;">
		<!-- 左边面板【start】 -->
		<div class="layui-col-md10" id="id_panel_left_grid" style="width:100%;">
			<div class="layui-panel" style="overflow: auto; padding-top: 0.2rem;">
				<div class="mid-content">
					
					<table class="layui-hide" id="main_table"></table>
					 
	<script type="text/html" id="toolbarDemo">
		<div class="layui-btn-container">
			<a class="layui-btn layui-btn-xs layui-btn-normal" onclick="addPage()"><i class="layui-icon layui-icon-add-circle"></i>新增</a>
			<a class="layui-btn layui-btn-xs layui-btn-normal" onclick="workFlowPage()"><i class="layui-icon layui-icon-search"></i>流程图示</a>
		</div>
	</script>


					<!-- 引用字段TPL自定义脚本 -->
					<th:block th:include="include/gird-tpl :: TPLScript"/>
					
					<script th:inline="javascript">

						var tableData = [];
						layui.use(function () {
							var table = layui.table;
							var layer = layui.layer;
							var $ = layui.jquery;
							var treeTable = layui.treeTable;

							var colmsg = [(${dto.colGrids})];
							var colNew = [];
							for(var i=0;i<colmsg.length;i++){
								if(colmsg[i].title != '序号'){//去除序号列
									colNew.push(colmsg[i]);
								}
							}

							// 渲染
							var inst = treeTable.render({
								id:'treeTableId',
								elem: '#main_table',
								url:'[(${dto.menu.pathGridRequest})]', // 此处为静态模拟数据，实际使用时需换成真实接口
								tree: {
									customName:{//自定义属性名
										children : 'children',
										isParent : 'isParent',
										name : 'setTypeStr',
										id:'id',
										pid:'pid'
									},
									view:{
										indent :25
									}
								},
								maxHeight: (window.innerHeight - 40) + 'px',
								toolbar: '#toolbarDemo',
								defaultToolbar: [
										/*{
									title: '刷新页面'
									,layEvent: 'LAYTABLE_REFRESH'
									,icon: 'layui-icon-refresh'
								}
										 */
								],
								cols: [colNew],
								page: false,
								//limit : 20,
								//limits : [20,50,200,500],
								done: function(res){
									//console.log("res",res);
									tableData = res.data;
									//树展开
									if(tableData!=null && tableData.length>0){
										for(var i=0;i<tableData.length;i++){
											if(tableData[i].children!=null && tableData[i].children.length>0){
												treeTable.expandNode('treeTableId', {
													index: i, // 第一行
													expandFlag: true // 展开
												});
												putTree(i,tableData[i].children,treeTable);
											}
										}
									}
								},
							});

							//treeTable.expandAll('treeTableId', true); // 展开全部节点，最新layui2.8的版本只能关闭无法展开

							// 工具栏事件
							treeTable.on('toolbar(main_table)', function(obj){
								//console.log(1111111);
								switch(obj.event){
									case 'LAYTABLE_REFRESH':
									{
										layer.confirm("确定刷新吗？",{
											btn: ['确定', '取消']
										}, function (index) {
											location.reload();
											layer.close(index);
										});
										break;
									}
									case 'LAYTABLE_EXPORT_DATA':
									{
										$.ajax({
											type: "POST",
											url: '[(${dto.menu.pathGridExportRequest})]',
											data: getConds(),
											success: function (data) {
												if (data.code == 0) {
													if(data.msg != undefined && data.msg.startsWith('http')) {
														window.open(data.msg);
													} else {
														layer.msg(data.msg);
													}
												} else {
													alert(data.msg);
												}
											}
										});
										break;
									}

								};
							});
						});
						//递归展开树
						function putTree(index,childrenList,treeTable){
							if(childrenList!=null && childrenList.length>0){
								for(var i=0;i<childrenList.length;i++){
									if(childrenList[i].children!=null && childrenList[i].children.length>0){
										treeTable.expandNode('treeTableId', {
											index: index+'-'+i, // 第一行
											expandFlag: true // 展开
										});
										putTree(index+'-'+i,childrenList[i].children,treeTable);
									}
								}
							}
						}

						//编辑
						function doEdit(id,parentId,childrenLength) {
							var w=($(window).width()*0.8);
							var h=($(window).height() - 50);
							window.sessionStorage.setItem("tableData", JSON.stringify(tableData));
							layer.open({
								title:'编辑',
								type: 2,
								area: [w+'px', h +'px'],
								fix: true, maxmin: false, shadeClose: true,
								shade:0.4,shade:0.5,
								content:'/web/business/tpShopStopPhaseSet/toEdit?id=' + id  + '&childrenLength='+ childrenLength
							});
						}

						// 删除
						function doDeleteOnTable(id,phaseNum,parentId,childrenLength) {
							//console.log('删除',id,phaseNum,parentId,childrenLength);
							if(childrenLength>0){
								layer.alert('您要删除的节点存在子节点，无法删除！若想删除请先删除该节点下的所有子节点！', {
									icon: 0,
									shadeClose: true,
									title: '温馨提示 '
								});
								return ;
							}

							layer.confirm('确定删除？ ', {icon: 3}, function(){
								layui.layer.msg('操作中', {
									icon: 16,
									shade: 0.01
								});
								//删除前查询是否有正处于该阶段的任务
								$.post('/api/inter/tpShopStopPhaseSet/deleteTrueBefore?id=' + id + '&phaseNum=' + phaseNum+ '&parentId=' + parentId ,function(res){
									if (res.code == 0) {//无正处于该阶段的任务
										deleteTrue(id,phaseNum,parentId);
									} else {//有正处于该阶段的任务
										layer.confirm('有跟踪单正处于该阶段未完成，删除后这些跟踪单将无法完成，确定要继续？ ',{icon: 0}, function(){
											deleteTrue(id,phaseNum,parentId);
										}, function(){layer.close();}
										);
									}
								});
							}, function(){layer.close();}
							);
						}
						function deleteTrue(id,phaseNum,parentId) {
							$.post('/api/inter/tpShopStopPhaseSet/deleteTrue?id=' + id + '&phaseNum=' + phaseNum+ '&parentId=' + parentId ,function(trueRes){
								if (trueRes.code == 0) {
									layer.msg(trueRes.msg);
									layer.close();
									location.reload();
								} else {
									layer.close();
									layer.msg(trueRes.msg);
								}
							});
						}


						// 新增
						function addPage(){
							var w=($(window).width()*0.8);
							var h=($(window).height() - 50);
							window.sessionStorage.setItem("tableData", JSON.stringify(tableData));
							layer.open({
								title:'新增',
								type: 2,
								area: [w+'px', h +'px'],
								fix: true, maxmin: false, shadeClose: true, shade:0.4,shade:0.5,
								content:'/web/business/tpShopStopPhaseSet/toAdd'
							});
						}

						// 图例
						function workFlowPage(){
							var w=($(window).width()*0.8);
							var h=($(window).height() - 50);
							window.sessionStorage.setItem("tableData", JSON.stringify(tableData));
							layer.open({
								title:'流程图示',
								type: 2,
								area: [w+'px', h +'px'],
								fix: true, maxmin: false, shadeClose: true, shade:0.4,shade:0.5,
								content:'/web/business/tpShopStopPhaseSet/workFlow'
							});
						}

					$('body').on("mouseenter",".layui-table-body tr",function () {
					    $(this).siblings().find("div").css("color","#142A48");
					    $(this).find("div").css("color","#4DA1FF");
					})
					</script>
				</div>
			</div>
		</div>
		<!-- 左边面板【end】 -->

		<!-- 引用按钮自定义脚本 -->
		<th:block th:with="menuId=${dto.menuId}" th:include="include/gird-btn :: BTNScript(menuId)"/>

		
	</div>
	
	<script type="text/javascript">
	$(function() {
		$('#id_panel_left_grid').css('height', (window.innerHeight - 40) + 'px');
		$('#id_form_search').find('a[data-id="icon-to-show"]').hide();
	});
	</script>
</body>
		
</html>